//
// Created by 吴竹亚 on 2023/3/14.
//
#include <stdlib.h>
#include <stdio.h>

#define MAXSIZE 40
typedef struct {
    int no;
    int score;
} Stu;

typedef struct {
    // 左指针，指向队列中第一个元素
    int left;
    // 右指针，指向队列中最后一个元素
    int right;
    Stu *stu;
} SqQueue;

void initQueue(SqQueue &sqQueue) {
    Stu *stu = new Stu[MAXSIZE];
    sqQueue.stu = stu;
    sqQueue.left = 0;
    sqQueue.right = 0;
}

int queueLength(SqQueue &sqQueue) {
    return sqQueue.right - sqQueue.left;
}


void deleteSqQueue(SqQueue &sqQueue, Stu &e) {        //出队，并放入e中。
    e = *(sqQueue.stu + sqQueue.left);
    sqQueue.left++;

}

void enterSqQueue(SqQueue &sqQueue, Stu &e) {       //将数据元素e入队。
    if (sqQueue.right < MAXSIZE - 1) {
        *(sqQueue.stu + sqQueue.right) = e;
        sqQueue.right++;
    } else {
        printf("队列已满");
    }
}

void initValue(SqQueue &sqQueue) {
    for (int i = 0; i < 10; ++i) {
        Stu stu;
        stu.no = i + 43;
        stu.score = 100 - i * 10;
        enterSqQueue(sqQueue, stu);
    }
}

void show(SqQueue &sqQueue) {
    for (int i = sqQueue.left; i < sqQueue.right; ++i) {
        printf("the %d stu, no is %d, score is %d\n", i - sqQueue.left + 1, (sqQueue.stu + i)->no,
               (sqQueue.stu + i)->score);
    }
}

int main() {
    //定义一个循环队列
    SqQueue sqQueue;
    initQueue(sqQueue);
    //将十个同学信息入队
    initValue(sqQueue);
    //输出所有数据
    show(sqQueue);
    printf("-============================\n");

    //出队一个数据元素，
    Stu s1;
    deleteSqQueue(sqQueue, s1);
    printf("the delete stu, no is %d, score is %d\n", s1.no, s1.score);
    //输出所有数据
    show(sqQueue);
    printf("-============================\n");

    //入队一个数据元素（自己学号-1）同学
    Stu s2 = {42, 3};
    enterSqQueue(sqQueue, s2);
    //输出所有数据
    show(sqQueue);
    printf("-============================\n");


    //入队一个数据元素（自己学号-1）同学
    Stu s3 = {41, 2};
    enterSqQueue(sqQueue, s3);
    //输出所有数据
    show(sqQueue);
    return 0;
}
